﻿using GameBasic;
using UnityEngine;

namespace VCity
{
    public struct AdsData
    {
        public string id;
        public string text0;
        public string text1;
        public string texture;
        public string video;
        public string link;

        // runtime
        public string[] texts;

        public bool HasText => !string.IsNullOrEmpty(text0);
        public bool HasTexture => !string.IsNullOrEmpty(texture);
        public bool HasVideo => !string.IsNullOrEmpty(video);
        public bool HasLink => !string.IsNullOrEmpty(link);

        public void Init()
        {
            if (!string.IsNullOrEmpty(text1))
                texts = new string[] { text0, text1 };
        }

        public string GetText(int i)
        {
            if (texts != null)
            {
                i = Mathf.Clamp(i, 0, texts.Length - 1);
                return texts[i];
            }
            else if (i == 0)
            {
                return text0;
            }

            return null;
        }

        public override string ToString()
        {
            return $"{id}\n{GetText(0)}\n{texture}\n{video}\n{link}";
        }
    }
}